import qrcode
import cv2
import numpy as np
 
data = 'https://www.10zhan.com'
qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=10, border=4)
qr.add_data(data)
qr.make(fit=True)
qr_img = qr.make_image(fill_color="black", back_color="white").convert('RGB')
 
background_path = './status/heihei.png'
background = cv2.imread(background_path)
background = cv2.resize(background, (qr_img.size[0], qr_img.size[1]))
background_gray = cv2.cvtColor(background, cv2.COLOR_BGR2GRAY)
 
qr_img_gray = cv2.cvtColor(np.array(qr_img), cv2.COLOR_RGB2GRAY)
_, qr_mask = cv2.threshold(qr_img_gray, 0, 255, cv2.THRESH_BINARY_INV)
 
qr_combined = cv2.bitwise_not(qr_mask) & background_gray
qr_combined = cv2.bitwise_not(qr_combined)
 
cv2.imwrite('./status/qrcode4.png', qr_combined)